<template>
	<div id="appRoot">
		<sidebar>
			<card label="入库文档">
				<div class="from-query">
					<el-form :inline="true" class="demo-form-inline">
						<el-form-item label="搜索">
							<el-input size="small" v-model="queryData.name" placeholder="文档名/导入人/单位关键字"></el-input>
						</el-form-item>
						<el-form-item label="出处">
							<el-select v-model="queryData.source" placeholder="全部">
								<el-option label="全部" value="-1"></el-option>
								<el-option v-for="item in sourceConfig" :label="item.name" :value="item.id" :key="item.id"></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="入库时间">
							<el-date-picker
									v-model="queryDate"
									type="daterange"
									placeholder="选择时间范围">
							</el-date-picker>
						</el-form-item>
						<el-form-item>
							<el-button size="small" type="primary" @click="getTableData()">查询</el-button>
						</el-form-item>
					</el-form>
				</div>
			</card>
			<div class="table-container" v-loading.body="loading">
				<template v-if="tableDataError">
					<table-data-fail type="error"></table-data-fail>
				</template>
				<template v-else-if="tableData.length > 0">
					<el-table
							:data="tableData"
							stripe
							border
							style="width: 100%">
						<el-table-column
								align="center"
								header-align="left"
								label="文档标题">
							<template scope="scope">
								{{scope.row.name}}
								{{scope.row.fileType | fileType}}
							</template>
						</el-table-column>
						<el-table-column
								prop="source"
								align="center"
								header-align="left"
								label="出处">
						</el-table-column>
						<el-table-column
								prop="merName"
								align="center"
								header-align="left"
								label="导入单位">
						</el-table-column>
						<el-table-column
								prop="staffCode"
								align="center"
								header-align="left"
								label="导入人">
						</el-table-column>
						<el-table-column
								prop="date"
								align="center"
								header-align="left"
								label="时间">
						</el-table-column>
					</el-table>
					<div class="pagination-wrapper">
						<el-pagination
								@current-change="getTableData"
								:current-page.sync="paginationData.currentPage"
								:page-size="paginationData.pageSize"
								layout="prev, pager, next, jumper"
								:total="paginationData.total">
						</el-pagination>
					</div>
				</template>
				<template v-else>
					<table-data-fail type="empty"></table-data-fail>
				</template>
			</div>
		</sidebar>
	</div>
</template>

<script>
	import sidebar from 'components/layout/sidebar.vue'
	import card from 'components/layout/card.vue'
	import tableDataFail from 'components/layout/tableDataFail.vue'
    import ajax from 'common/ajax.js'
    import ajaxUrls from 'common/ajaxUrls.js'
    import {sourceConfig} from 'common/unitQry.js'
	export default{
		data(){
			return{
				loading: false,
                queryDate: [],
				queryData: {
				    name: '',
                    source: '-1',
                    startDate: '',
                    endDate: ''
				},
				paginationData:{
					currentPage: 1,
					pageSize: 10,
					total: 0
				},
				tableDataError: false,
				tableData: [],

                sourceConfig: [],
			}
		},
        mounted(){
            sourceConfig().then(data => {
                this.sourceConfig = data.data.items || [];
            });
            this.getTableData();
        },
		filters: {
            fileType(val){
                val = String(val);
                let text = '';
                switch(val){
					case '1':
					    text = '文本';
					    break;
                    case '2':
                        text = 'word';
                        break;
                    case '3':
                        text = 'excel';
                        break;
					default:
					    break;
				}
				return text;
			},
		},
		methods: {
            getTableData(current){
                if(this.queryDate[1]){
                    this.queryData.startDate = moment(this.queryDate[0]).format('YYYY-MM-DD');
                    this.queryData.endDate = moment(this.queryDate[1]).format('YYYY-MM-DD');
                }else{
                    this.queryData.startDate = '';
                    this.queryData.endDate = '';
                }
                let data = {
                    pageNum:  current || this.paginationData.currentPage,
                    pageRow: this.paginationData.pageSize
                };
                data = Object.assign(data, this.queryData);
                ajax({
                    method: 'post',
                    url: ajaxUrls.apiUrl.FileConfig,
                    action: 'qryFileConfig',
                    data: data
                }).then(function (data) {
                    this.tableData = data.data.items || [];
                    this.paginationData.total = data.data.totalNum || 0;
                }.bind(this)).catch(function (err) {

                })
            },
		},
		components:{
			sidebar,
			card,
			tableDataFail
		}
	}
</script>

<style lang="scss">
</style>